import { ApiProperty } from '@nestjs/swagger';
import {
  PrimaryGeneratedColumn,
  CreateDateColumn,
  UpdateDateColumn,
  Column,
  ManyToOne,
  OneToMany,
  Entity,
  JoinColumn,
} from 'typeorm';

export enum StatusComment {
  Pass = 'pass',
  Block = 'block',
  Review = 'review',
}

@Entity('comments')
export class Comment {
  @PrimaryGeneratedColumn()
  id: number;

  @ApiProperty({ description: 'ip地址' })
  @Column({
    comment: 'ip地址',
    default: null,
  })
  ip: string;

  @ApiProperty({ description: '评论者的环境' })
  @Column({ comment: '评论者的环境', default: null })
  ua: string;

  @ApiProperty({ description: '评论用户头像' })
  @Column({
    comment: '评论用户头像',
    default: null,
  })
  avatar: string;

  @ApiProperty({ description: '评论用户邮箱' })
  @Column({
    comment: '评论用户邮箱',
    default: null,
  })
  email: string;

  @ApiProperty({ description: '评论人名称' })
  @Column({
    comment: '评论人名称',
    default: null,
  })
  name: string;

  @ApiProperty({ description: '被评论人名称' })
  @Column({
    comment: '被评论人名称',
    nullable: true,
    default: null,
  })
  replyName: string;

  @ApiProperty({ description: '被评论人邮箱' })
  @Column({
    comment: '被评论人邮箱',
    nullable: true,
    default: null,
  })
  replyEmail: string;

  @ApiProperty({ description: '状态' })
  @Column({
    type: 'enum',
    comment: '状态 pass 正常， block 不通过, review - 需要人工复查',
    nullable: false,
    enum: StatusComment,
    default: StatusComment.Pass,
  })
  status: string;

  @ApiProperty({ description: '相关检测结果详细信息' })
  @Column({
    type: 'text',
    comment: '相关检测结果详细信息',
  })
  suggestion: string;

  @ApiProperty({ description: '是否置顶' })
  @Column({
    comment: '是否置顶 false - 不置顶 , true - 置顶',
    default: false,
  })
  putTop: boolean;

  @ApiProperty({ description: '是否是管理员' })
  @Column({
    comment: '是否是管理员 false - 不是 , true - 是',
    default: false,
  })
  isAdmin: boolean;

  @ApiProperty({ description: '评论父级' })
  @ManyToOne(() => Comment, (comment) => comment.children, {
    nullable: true,
  })
  parent: Comment;

  @ApiProperty({ description: '评论子级' })
  @OneToMany(() => Comment, (comment) => comment.parent)
  children: Comment[];

  @ApiProperty({ description: '内容' })
  @Column({
    comment: '内容',
    default: null,
  })
  content: string;

  @ApiProperty({ description: '锚点' })
  @Column({
    comment: '锚点',
    default: null,
  })
  anchor: string;

  @ApiProperty({ description: '资源id' })
  @Column({
    comment: '资源id',
    nullable: false,
  })
  resourceId: string;

  @ApiProperty({ description: '创建时间' })
  @CreateDateColumn({
    type: 'timestamp',
    comment: '创建时间',
  })
  createTime: Date;

  @ApiProperty({ description: '更新时间' })
  @UpdateDateColumn({
    type: 'timestamp',
    comment: '更新时间',
  })
  updateTime: Date;
}
